/*
 * @Author: your name
 * @Date: 2020-10-03 12:51:38
 * @LastEditTime: 2020-10-03 14:16:51
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \woniutaofang\lib\pages\home\widgets\collectionarea_widget.dart
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:woniutaofang/pages/home/widgets/like_button_widget.dart';
import 'package:woniutaofang/utils/dimens.dart';
import 'package:woniutaofang/utils/toast.dart';
import 'package:woniutaofang/utils/utils.dart';

class CollectionAreaWidget extends StatefulWidget {
  String title;
  List tagList;
  CollectionAreaWidget(this.title, this.tagList, {Key key}) : super(key: key);
  @override
  _CollectionAreaWidgetState createState() => _CollectionAreaWidgetState();
}

class _CollectionAreaWidgetState extends State<CollectionAreaWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 5.0),
      // height: 60.0,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                widget.title,
                style: TextStyle(
                    fontSize: ScreenUtil().setSp(36),
                    fontWeight: FontWeight.bold),
              ),
              LikeButton(
                size: 50.0,
              ),
            ],
          ),
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Wrap(
                spacing: 5.0,
                children: widget.tagList
                    .map(
                      (language) => Container(
                        child: _GoodsItemTag(
                          text: language,
                          heigth: 26.0,
                          color: Theme.of(context).errorColor,
                        ),
                      ),
                    )
                    .toList(),
              ),
            ],
          )
        ],
      ),
    );
  }
}

class _GoodsItemTag extends StatelessWidget {
  const _GoodsItemTag({Key key, this.color, this.text, this.heigth = 16.0})
      : super(key: key);

  final Color color;
  final String text;
  final double heigth;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 4.0),
      margin: const EdgeInsets.only(right: 4.0),
      decoration: BoxDecoration(
        color: color,
        borderRadius: BorderRadius.circular(2.0),
      ),
      height: heigth,
      alignment: Alignment.center,
      child: Text(
        text,
        style: const TextStyle(
          color: Colors.white,
          fontSize: Dimens.font_sp10,
        ),
      ),
    );
  }
}
